/*
 * Copyright 2025 The Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *@file    : feature_database.h
 *@brief   : feature database 
 *@authors : zhanglei, zhanglei_723@126.com
 *@version : v1.0
 *@data    : 2025/8/30
 *
 */

#ifndef FEATURE_DATABASE_H
#define FEATURE_DATABASE_H

#include <Eigen/Eigen>
#include <memory>
#include <mutex>
#include <unordered_map>
#include <vector>

#include "feature/feature.h"

namespace feature {

class FeatureDatabase {
public:
  /**
   * @brief Default constructor
   */
  FeatureDatabase() {}

  void UpdateFeatureDatabase(const uint8_t& camera_id, const uint64_t& frame_id, const uint64_t& feature_id, const FeaturePoint& feature);
  bool GetFeaturePoint(FeaturePoint& feature_point, const uint8_t& camera_id, const uint64_t& frame_id, const uint64_t& feature_id);
  std::map<uint64_t, FeaturePoint> GetOneFrameFeaturePoints(const uint8_t& camera_id, const uint64_t& frame_id);

  uint32_t Size();

  std::unordered_map<uint64_t, std::shared_ptr<Feature>> GetFeatureDatabase();
  
  void UpdateLandmark(const uint64_t& feature_id, const std::shared_ptr<Feature>& feature, const Vector3d& world_point);
  void EraseLandmarkFromFrameId(const uint8_t& camera_id, const uint64_t& frame_id);
protected:
  /// Our lookup array that allow use to query based on ID; 
  /// map: feature id and feature
  std::unordered_map<uint64_t, std::shared_ptr<Feature>> feature_database_;
};

} // namespace feature

#endif /* FEATURE_DATABASE_H */